<?php
/**
 * Nweb Editor
 *
 * This script is protected by copyright. Its use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    source
 * @package     pl.nweb.editor.datatype
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2012 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id$
 * @link        https://nweb-editor.googlecode.com
 * @link        http://editor.nweb.pl
 */

namespace pl\nweb\editor\datatype\content;

/**
 * Atrybut
 *
 * @category    source
 * @package     pl.nweb.editor.datatype
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2012 Krzysztof Kardasz
 * @version     1.0 $Id$
 */
abstract class Attribute
{
    /**
     * Parametry wywołania
     *
     * @var array
     */
    private $_params = array();

    /**
     * Konstruktor
     *
     * @param  array $params parametry
     */
    final public function __construct(array $params = array())
    {
        $this->_params = $params;
        $this->_init();
    }

    /**
     * Pobranie wartości parametru
     *
     * @param string $name nazwa parametru
     * @param mixed $default domyślna wartość
     * @return void
     */
    protected function _getParam($name, $default = null)
    {
        if(isset($this->_params[$name])) {
            return $this->_params[$name];
        }
        return $default;
    }

    /**
     * Inicjacja
     *
     * @return void
     */
    protected function _init()
    {}

    /**
     * Serializacja obiektu
     *
     * @return string
     */
    abstract public function serialize();

    /**
     * Deserializacja obiektu
     *
     * @param  string $data dane
     * @return void
     */
    abstract public function unserialize($data);
}